{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "#%%\n",
    "from vnpy_ctastrategy.backtesting import BacktestingEngine, OptimizationSetting\n",
    "from vnpy_ctastrategy.strategies.atr_rsi_strategy import (\n",
    "    AtrRsiStrategy,\n",
    ")\n",
    "from datetime import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "#%%\n",
    "engine = BacktestingEngine()\n",
    "engine.set_parameters(\n",
    "    vt_symbol=\"IF888.CFFEX\",\n",
    "    interval=\"1m\",\n",
    "    start=datetime(2019, 1, 1),\n",
    "    end=datetime(2019, 4, 30),\n",
    "    rate=0.3/10000,\n",
    "    slippage=0.2,\n",
    "    size=300,\n",
    "    pricetick=0.2,\n",
    "    capital=1_000_000,\n",
    ")\n",
    "engine.add_strategy(AtrRsiStrategy, {})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2021-11-24 18:04:11.374753\t开始加载历史数据\n",
      "2021-11-24 18:04:11.374753\t加载进度：# [0%]\n",
      "2021-11-24 18:04:11.416207\t加载进度：# [9%]\n",
      "2021-11-24 18:04:11.417844\t加载进度：## [18%]\n",
      "2021-11-24 18:04:11.418990\t加载进度：### [28%]\n",
      "2021-11-24 18:04:11.419649\t加载进度：#### [37%]\n",
      "2021-11-24 18:04:11.420638\t加载进度：##### [46%]\n",
      "2021-11-24 18:04:11.421227\t加载进度：###### [55%]\n",
      "2021-11-24 18:04:11.421882\t加载进度：####### [65%]\n",
      "2021-11-24 18:04:11.422284\t加载进度：######## [74%]\n",
      "2021-11-24 18:04:11.422771\t加载进度：######### [83%]\n",
      "2021-11-24 18:04:11.423777\t加载进度：########## [92%]\n",
      "2021-11-24 18:04:11.423777\t历史数据加载完成，数据量：0\n",
      "2021-11-24 18:04:11.423777\t策略初始化完成\n",
      "2021-11-24 18:04:11.423777\t开始回放历史数据\n",
      "2021-11-24 18:04:11.423777\t历史数据不足，回测终止\n",
      "2021-11-24 18:04:11.423777\t开始计算逐日盯市盈亏\n",
      "2021-11-24 18:04:11.423777\t成交记录为空，无法计算\n",
      "2021-11-24 18:04:11.423777\t开始计算策略统计指标\n",
      "2021-11-24 18:04:11.423777\t------------------------------\n",
      "2021-11-24 18:04:11.423777\t首个交易日：\t\n",
      "2021-11-24 18:04:11.423777\t最后交易日：\t\n",
      "2021-11-24 18:04:11.423777\t总交易日：\t0\n",
      "2021-11-24 18:04:11.423777\t盈利交易日：\t0\n",
      "2021-11-24 18:04:11.423777\t亏损交易日：\t0\n",
      "2021-11-24 18:04:11.423777\t起始资金：\t1,000,000.00\n",
      "2021-11-24 18:04:11.424777\t结束资金：\t0.00\n",
      "2021-11-24 18:04:11.424777\t总收益率：\t0.00%\n",
      "2021-11-24 18:04:11.424777\t年化收益：\t0.00%\n",
      "2021-11-24 18:04:11.424777\t最大回撤: \t0.00\n",
      "2021-11-24 18:04:11.424777\t百分比最大回撤: 0.00%\n",
      "2021-11-24 18:04:11.424777\t最长回撤天数: \t0\n",
      "2021-11-24 18:04:11.424777\t总盈亏：\t0.00\n",
      "2021-11-24 18:04:11.424777\t总手续费：\t0.00\n",
      "2021-11-24 18:04:11.424777\t总滑点：\t0.00\n",
      "2021-11-24 18:04:11.424777\t总成交金额：\t0.00\n",
      "2021-11-24 18:04:11.425777\t总成交笔数：\t0\n",
      "2021-11-24 18:04:11.425777\t日均盈亏：\t0.00\n",
      "2021-11-24 18:04:11.425777\t日均手续费：\t0.00\n",
      "2021-11-24 18:04:11.425777\t日均滑点：\t0.00\n",
      "2021-11-24 18:04:11.425777\t日均成交金额：\t0.00\n",
      "2021-11-24 18:04:11.425777\t日均成交笔数：\t0\n",
      "2021-11-24 18:04:11.425777\t日均收益率：\t0.00%\n",
      "2021-11-24 18:04:11.425777\t收益标准差：\t0.00%\n",
      "2021-11-24 18:04:11.425777\tSharpe Ratio：\t0.00\n",
      "2021-11-24 18:04:11.425777\t收益回撤比：\t0.00\n",
      "2021-11-24 18:04:11.425777\t策略统计指标计算完成\n"
     ]
    }
   ],
   "source": [
    "#%%\n",
    "engine.load_data()\n",
    "engine.run_backtesting()\n",
    "df = engine.calculate_result()\n",
    "engine.calculate_statistics()\n",
    "engine.show_chart()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2021-11-24 18:12:12.994470\t开始执行遗传算法优化\n",
      "2021-11-24 18:12:12.994557\t参数优化空间：9\n",
      "2021-11-24 18:12:12.994557\t每代族群总数：100\n",
      "2021-11-24 18:12:12.994557\t优良筛选个数：80\n",
      "2021-11-24 18:12:12.994557\t迭代次数：30\n",
      "2021-11-24 18:12:12.994557\t交叉概率：95%\n",
      "2021-11-24 18:12:12.994557\t突变概率：5%\n"
     ]
    },
    {
     "ename": "RemoteError",
     "evalue": "\n---------------------------------------------------------------------------\nTraceback (most recent call last):\n  File \"c:\\vnstudio\\lib\\multiprocessing\\managers.py\", line 234, in serve_client\n    request = recv()\n  File \"c:\\vnstudio\\lib\\multiprocessing\\connection.py\", line 251, in recv\n    return _ForkingPickler.loads(buf.getbuffer())\nAttributeError: Can't get attribute 'scalar' on <module 'numpy.core.multiarray' from 'c:\\\\vnstudio\\\\lib\\\\site-packages\\\\numpy\\\\core\\\\multiarray.py'>\n---------------------------------------------------------------------------",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mRemoteTraceback\u001b[0m                           Traceback (most recent call last)",
      "\u001b[1;31mRemoteTraceback\u001b[0m: \n\"\"\"\nTraceback (most recent call last):\n  File \"c:\\vnstudio\\lib\\multiprocessing\\pool.py\", line 121, in worker\n    result = (True, func(*args, **kwds))\n  File \"c:\\vnstudio\\lib\\multiprocessing\\pool.py\", line 44, in mapstar\n    return list(map(*args))\n  File \"c:\\vnstudio\\lib\\site-packages\\vnpy\\trader\\optimize.py\", line 229, in ga_evaluate\n    cache[tp] = result\n  File \"<string>\", line 2, in __setitem__\n  File \"c:\\vnstudio\\lib\\multiprocessing\\managers.py\", line 811, in _callmethod\n    raise convert_to_error(kind, result)\nmultiprocessing.managers.RemoteError: \n---------------------------------------------------------------------------\nTraceback (most recent call last):\n  File \"c:\\vnstudio\\lib\\multiprocessing\\managers.py\", line 234, in serve_client\n    request = recv()\n  File \"c:\\vnstudio\\lib\\multiprocessing\\connection.py\", line 251, in recv\n    return _ForkingPickler.loads(buf.getbuffer())\nAttributeError: Can't get attribute 'scalar' on <module 'numpy.core.multiarray' from 'c:\\\\vnstudio\\\\lib\\\\site-packages\\\\numpy\\\\core\\\\multiarray.py'>\n---------------------------------------------------------------------------\n\"\"\"",
      "\nThe above exception was the direct cause of the following exception:\n",
      "\u001b[1;31mRemoteError\u001b[0m                               Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-6-b016d355a84b>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[0msetting\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0madd_parameter\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"atr_ma_length\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m10\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m30\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m10\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 6\u001b[1;33m \u001b[0mengine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrun_ga_optimization\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msetting\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mc:\\vnstudio\\lib\\site-packages\\vnpy_ctastrategy\\backtesting.py\u001b[0m in \u001b[0;36mrun_ga_optimization\u001b[1;34m(self, optimization_setting, output)\u001b[0m\n\u001b[0;32m    557\u001b[0m             \u001b[0moptimization_setting\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    558\u001b[0m             \u001b[0mget_target_value\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 559\u001b[1;33m             \u001b[0moutput\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0moutput\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    560\u001b[0m         )\n\u001b[0;32m    561\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\vnstudio\\lib\\site-packages\\vnpy\\trader\\optimize.py\u001b[0m in \u001b[0;36mrun_ga_optimization\u001b[1;34m(evaluate_func, optimization_setting, key_func, max_workers, population_size, ngen_size, output)\u001b[0m\n\u001b[0;32m    199\u001b[0m             \u001b[0mmutpb\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    200\u001b[0m             \u001b[0mngen\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 201\u001b[1;33m             \u001b[0mverbose\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    202\u001b[0m         )\n\u001b[0;32m    203\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\vnstudio\\lib\\site-packages\\deap\\algorithms.py\u001b[0m in \u001b[0;36meaMuPlusLambda\u001b[1;34m(population, toolbox, mu, lambda_, cxpb, mutpb, ngen, stats, halloffame, verbose)\u001b[0m\n\u001b[0;32m    299\u001b[0m     \u001b[1;31m# Evaluate the individuals with an invalid fitness\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    300\u001b[0m     \u001b[0minvalid_ind\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mind\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mind\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mpopulation\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mind\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfitness\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalid\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 301\u001b[1;33m     \u001b[0mfitnesses\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtoolbox\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmap\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtoolbox\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mevaluate\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0minvalid_ind\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    302\u001b[0m     \u001b[1;32mfor\u001b[0m \u001b[0mind\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfit\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minvalid_ind\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfitnesses\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    303\u001b[0m         \u001b[0mind\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfitness\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalues\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfit\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\vnstudio\\lib\\multiprocessing\\pool.py\u001b[0m in \u001b[0;36mmap\u001b[1;34m(self, func, iterable, chunksize)\u001b[0m\n\u001b[0;32m    288\u001b[0m         \u001b[1;32min\u001b[0m \u001b[0ma\u001b[0m \u001b[0mlist\u001b[0m \u001b[0mthat\u001b[0m \u001b[1;32mis\u001b[0m \u001b[0mreturned\u001b[0m\u001b[1;33m.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    289\u001b[0m         '''\n\u001b[1;32m--> 290\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_map_async\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfunc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0miterable\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmapstar\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mchunksize\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    291\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    292\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0mstarmap\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0miterable\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mchunksize\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\vnstudio\\lib\\multiprocessing\\pool.py\u001b[0m in \u001b[0;36mget\u001b[1;34m(self, timeout)\u001b[0m\n\u001b[0;32m    681\u001b[0m             \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_value\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    682\u001b[0m         \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 683\u001b[1;33m             \u001b[1;32mraise\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_value\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    684\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    685\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m_set\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mobj\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mRemoteError\u001b[0m: \n---------------------------------------------------------------------------\nTraceback (most recent call last):\n  File \"c:\\vnstudio\\lib\\multiprocessing\\managers.py\", line 234, in serve_client\n    request = recv()\n  File \"c:\\vnstudio\\lib\\multiprocessing\\connection.py\", line 251, in recv\n    return _ForkingPickler.loads(buf.getbuffer())\nAttributeError: Can't get attribute 'scalar' on <module 'numpy.core.multiarray' from 'c:\\\\vnstudio\\\\lib\\\\site-packages\\\\numpy\\\\core\\\\multiarray.py'>\n---------------------------------------------------------------------------"
     ]
    }
   ],
   "source": [
    "setting = OptimizationSetting()\n",
    "setting.set_target(\"sharpe_ratio\")\n",
    "setting.add_parameter(\"atr_length\", 25, 27, 1)\n",
    "setting.add_parameter(\"atr_ma_length\", 10, 30, 10)\n",
    "\n",
    "engine.run_ga_optimization(setting)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2021-11-24 18:04:22.356872\t开始执行穷举算法优化\n",
      "2021-11-24 18:04:22.356872\t参数优化空间：9\n",
      "2021-11-24 18:04:23.423582\t穷举算法优化完成，耗时1秒\n",
      "2021-11-24 18:04:23.589523\t参数：{'atr_length': 25, 'atr_ma_length': 10}, 目标：0\n",
      "2021-11-24 18:04:23.590532\t参数：{'atr_length': 25, 'atr_ma_length': 20}, 目标：0\n",
      "2021-11-24 18:04:23.590532\t参数：{'atr_length': 25, 'atr_ma_length': 30}, 目标：0\n",
      "2021-11-24 18:04:23.590532\t参数：{'atr_length': 26, 'atr_ma_length': 10}, 目标：0\n",
      "2021-11-24 18:04:23.590532\t参数：{'atr_length': 26, 'atr_ma_length': 20}, 目标：0\n",
      "2021-11-24 18:04:23.590532\t参数：{'atr_length': 26, 'atr_ma_length': 30}, 目标：0\n",
      "2021-11-24 18:04:23.590532\t参数：{'atr_length': 27, 'atr_ma_length': 10}, 目标：0\n",
      "2021-11-24 18:04:23.590532\t参数：{'atr_length': 27, 'atr_ma_length': 20}, 目标：0\n",
      "2021-11-24 18:04:23.590848\t参数：{'atr_length': 27, 'atr_ma_length': 30}, 目标：0\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[(\"{'atr_length': 25, 'atr_ma_length': 10}\",\n",
       "  0,\n",
       "  {'start_date': '',\n",
       "   'end_date': '',\n",
       "   'total_days': 0,\n",
       "   'profit_days': 0,\n",
       "   'loss_days': 0,\n",
       "   'capital': 1000000,\n",
       "   'end_balance': 0,\n",
       "   'max_drawdown': 0,\n",
       "   'max_ddpercent': 0,\n",
       "   'max_drawdown_duration': 0,\n",
       "   'total_net_pnl': 0,\n",
       "   'daily_net_pnl': 0,\n",
       "   'total_commission': 0,\n",
       "   'daily_commission': 0,\n",
       "   'total_slippage': 0,\n",
       "   'daily_slippage': 0,\n",
       "   'total_turnover': 0,\n",
       "   'daily_turnover': 0,\n",
       "   'total_trade_count': 0,\n",
       "   'daily_trade_count': 0,\n",
       "   'total_return': 0,\n",
       "   'annual_return': 0,\n",
       "   'daily_return': 0,\n",
       "   'return_std': 0,\n",
       "   'sharpe_ratio': 0,\n",
       "   'return_drawdown_ratio': 0}),\n",
       " (\"{'atr_length': 25, 'atr_ma_length': 20}\",\n",
       "  0,\n",
       "  {'start_date': '',\n",
       "   'end_date': '',\n",
       "   'total_days': 0,\n",
       "   'profit_days': 0,\n",
       "   'loss_days': 0,\n",
       "   'capital': 1000000,\n",
       "   'end_balance': 0,\n",
       "   'max_drawdown': 0,\n",
       "   'max_ddpercent': 0,\n",
       "   'max_drawdown_duration': 0,\n",
       "   'total_net_pnl': 0,\n",
       "   'daily_net_pnl': 0,\n",
       "   'total_commission': 0,\n",
       "   'daily_commission': 0,\n",
       "   'total_slippage': 0,\n",
       "   'daily_slippage': 0,\n",
       "   'total_turnover': 0,\n",
       "   'daily_turnover': 0,\n",
       "   'total_trade_count': 0,\n",
       "   'daily_trade_count': 0,\n",
       "   'total_return': 0,\n",
       "   'annual_return': 0,\n",
       "   'daily_return': 0,\n",
       "   'return_std': 0,\n",
       "   'sharpe_ratio': 0,\n",
       "   'return_drawdown_ratio': 0}),\n",
       " (\"{'atr_length': 25, 'atr_ma_length': 30}\",\n",
       "  0,\n",
       "  {'start_date': '',\n",
       "   'end_date': '',\n",
       "   'total_days': 0,\n",
       "   'profit_days': 0,\n",
       "   'loss_days': 0,\n",
       "   'capital': 1000000,\n",
       "   'end_balance': 0,\n",
       "   'max_drawdown': 0,\n",
       "   'max_ddpercent': 0,\n",
       "   'max_drawdown_duration': 0,\n",
       "   'total_net_pnl': 0,\n",
       "   'daily_net_pnl': 0,\n",
       "   'total_commission': 0,\n",
       "   'daily_commission': 0,\n",
       "   'total_slippage': 0,\n",
       "   'daily_slippage': 0,\n",
       "   'total_turnover': 0,\n",
       "   'daily_turnover': 0,\n",
       "   'total_trade_count': 0,\n",
       "   'daily_trade_count': 0,\n",
       "   'total_return': 0,\n",
       "   'annual_return': 0,\n",
       "   'daily_return': 0,\n",
       "   'return_std': 0,\n",
       "   'sharpe_ratio': 0,\n",
       "   'return_drawdown_ratio': 0}),\n",
       " (\"{'atr_length': 26, 'atr_ma_length': 10}\",\n",
       "  0,\n",
       "  {'start_date': '',\n",
       "   'end_date': '',\n",
       "   'total_days': 0,\n",
       "   'profit_days': 0,\n",
       "   'loss_days': 0,\n",
       "   'capital': 1000000,\n",
       "   'end_balance': 0,\n",
       "   'max_drawdown': 0,\n",
       "   'max_ddpercent': 0,\n",
       "   'max_drawdown_duration': 0,\n",
       "   'total_net_pnl': 0,\n",
       "   'daily_net_pnl': 0,\n",
       "   'total_commission': 0,\n",
       "   'daily_commission': 0,\n",
       "   'total_slippage': 0,\n",
       "   'daily_slippage': 0,\n",
       "   'total_turnover': 0,\n",
       "   'daily_turnover': 0,\n",
       "   'total_trade_count': 0,\n",
       "   'daily_trade_count': 0,\n",
       "   'total_return': 0,\n",
       "   'annual_return': 0,\n",
       "   'daily_return': 0,\n",
       "   'return_std': 0,\n",
       "   'sharpe_ratio': 0,\n",
       "   'return_drawdown_ratio': 0}),\n",
       " (\"{'atr_length': 26, 'atr_ma_length': 20}\",\n",
       "  0,\n",
       "  {'start_date': '',\n",
       "   'end_date': '',\n",
       "   'total_days': 0,\n",
       "   'profit_days': 0,\n",
       "   'loss_days': 0,\n",
       "   'capital': 1000000,\n",
       "   'end_balance': 0,\n",
       "   'max_drawdown': 0,\n",
       "   'max_ddpercent': 0,\n",
       "   'max_drawdown_duration': 0,\n",
       "   'total_net_pnl': 0,\n",
       "   'daily_net_pnl': 0,\n",
       "   'total_commission': 0,\n",
       "   'daily_commission': 0,\n",
       "   'total_slippage': 0,\n",
       "   'daily_slippage': 0,\n",
       "   'total_turnover': 0,\n",
       "   'daily_turnover': 0,\n",
       "   'total_trade_count': 0,\n",
       "   'daily_trade_count': 0,\n",
       "   'total_return': 0,\n",
       "   'annual_return': 0,\n",
       "   'daily_return': 0,\n",
       "   'return_std': 0,\n",
       "   'sharpe_ratio': 0,\n",
       "   'return_drawdown_ratio': 0}),\n",
       " (\"{'atr_length': 26, 'atr_ma_length': 30}\",\n",
       "  0,\n",
       "  {'start_date': '',\n",
       "   'end_date': '',\n",
       "   'total_days': 0,\n",
       "   'profit_days': 0,\n",
       "   'loss_days': 0,\n",
       "   'capital': 1000000,\n",
       "   'end_balance': 0,\n",
       "   'max_drawdown': 0,\n",
       "   'max_ddpercent': 0,\n",
       "   'max_drawdown_duration': 0,\n",
       "   'total_net_pnl': 0,\n",
       "   'daily_net_pnl': 0,\n",
       "   'total_commission': 0,\n",
       "   'daily_commission': 0,\n",
       "   'total_slippage': 0,\n",
       "   'daily_slippage': 0,\n",
       "   'total_turnover': 0,\n",
       "   'daily_turnover': 0,\n",
       "   'total_trade_count': 0,\n",
       "   'daily_trade_count': 0,\n",
       "   'total_return': 0,\n",
       "   'annual_return': 0,\n",
       "   'daily_return': 0,\n",
       "   'return_std': 0,\n",
       "   'sharpe_ratio': 0,\n",
       "   'return_drawdown_ratio': 0}),\n",
       " (\"{'atr_length': 27, 'atr_ma_length': 10}\",\n",
       "  0,\n",
       "  {'start_date': '',\n",
       "   'end_date': '',\n",
       "   'total_days': 0,\n",
       "   'profit_days': 0,\n",
       "   'loss_days': 0,\n",
       "   'capital': 1000000,\n",
       "   'end_balance': 0,\n",
       "   'max_drawdown': 0,\n",
       "   'max_ddpercent': 0,\n",
       "   'max_drawdown_duration': 0,\n",
       "   'total_net_pnl': 0,\n",
       "   'daily_net_pnl': 0,\n",
       "   'total_commission': 0,\n",
       "   'daily_commission': 0,\n",
       "   'total_slippage': 0,\n",
       "   'daily_slippage': 0,\n",
       "   'total_turnover': 0,\n",
       "   'daily_turnover': 0,\n",
       "   'total_trade_count': 0,\n",
       "   'daily_trade_count': 0,\n",
       "   'total_return': 0,\n",
       "   'annual_return': 0,\n",
       "   'daily_return': 0,\n",
       "   'return_std': 0,\n",
       "   'sharpe_ratio': 0,\n",
       "   'return_drawdown_ratio': 0}),\n",
       " (\"{'atr_length': 27, 'atr_ma_length': 20}\",\n",
       "  0,\n",
       "  {'start_date': '',\n",
       "   'end_date': '',\n",
       "   'total_days': 0,\n",
       "   'profit_days': 0,\n",
       "   'loss_days': 0,\n",
       "   'capital': 1000000,\n",
       "   'end_balance': 0,\n",
       "   'max_drawdown': 0,\n",
       "   'max_ddpercent': 0,\n",
       "   'max_drawdown_duration': 0,\n",
       "   'total_net_pnl': 0,\n",
       "   'daily_net_pnl': 0,\n",
       "   'total_commission': 0,\n",
       "   'daily_commission': 0,\n",
       "   'total_slippage': 0,\n",
       "   'daily_slippage': 0,\n",
       "   'total_turnover': 0,\n",
       "   'daily_turnover': 0,\n",
       "   'total_trade_count': 0,\n",
       "   'daily_trade_count': 0,\n",
       "   'total_return': 0,\n",
       "   'annual_return': 0,\n",
       "   'daily_return': 0,\n",
       "   'return_std': 0,\n",
       "   'sharpe_ratio': 0,\n",
       "   'return_drawdown_ratio': 0}),\n",
       " (\"{'atr_length': 27, 'atr_ma_length': 30}\",\n",
       "  0,\n",
       "  {'start_date': '',\n",
       "   'end_date': '',\n",
       "   'total_days': 0,\n",
       "   'profit_days': 0,\n",
       "   'loss_days': 0,\n",
       "   'capital': 1000000,\n",
       "   'end_balance': 0,\n",
       "   'max_drawdown': 0,\n",
       "   'max_ddpercent': 0,\n",
       "   'max_drawdown_duration': 0,\n",
       "   'total_net_pnl': 0,\n",
       "   'daily_net_pnl': 0,\n",
       "   'total_commission': 0,\n",
       "   'daily_commission': 0,\n",
       "   'total_slippage': 0,\n",
       "   'daily_slippage': 0,\n",
       "   'total_turnover': 0,\n",
       "   'daily_turnover': 0,\n",
       "   'total_trade_count': 0,\n",
       "   'daily_trade_count': 0,\n",
       "   'total_return': 0,\n",
       "   'annual_return': 0,\n",
       "   'daily_return': 0,\n",
       "   'return_std': 0,\n",
       "   'sharpe_ratio': 0,\n",
       "   'return_drawdown_ratio': 0})]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "engine.run_bf_optimization(setting)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
